package com.itheima.Set.TreeSet;

import java.util.Collections;
import java.util.TreeSet;

public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

 /*   @Override
    public int compareTo(Student o) {
        //主要判断条件: 年龄升序
        *//*
            this: 表示要添加的元素
            o: 树中已有的元素
         *//*
        int result = this.age - o.age;
        //次要条件: 年龄相同时, 姓名降序
        int result1 = result == 0 ?  o.name.compareTo(this.name) : result;
        return result1;
    }
*/
    @Override
    public int compareTo(Student o){
        int result=this.age-o.age;
        int result1 = result == 0 ? this.name.compareTo(o.name) : result;
        return result;
    }

}
